package com.kate.mall.member.controller;

import com.kate.mall.common.utils.PageUtils;
import com.kate.mall.common.utils.R;
import com.kate.mall.member.entity.AddressEntity;
import com.kate.mall.member.service.AddressService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 收货地址表
 *
 * @author kate-chan
 * @email ccsu_loader@163.com
 * @date 2021-10-08 16:10:48
 */
@Api(tags = "AddressController", description = "收货地址表服务")
@RestController
@RequestMapping("user/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("user:address:list")
    @ApiOperation("获取所有收货地址表信息")
    @ApiImplicitParams(@ApiImplicitParam(name="params",required = false))
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = addressService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("user:address:info")
    @ApiOperation("获取指定id的收货地址表详情")
    public R info(@PathVariable("id") Integer id){
		AddressEntity address = addressService.getById(id);

        return R.ok().put("address", address);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("添加收货地址表信息")
    //@RequiresPermissions("user:address:save")
    public R save(@RequestBody AddressEntity address){
		addressService.save(address);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation("更新指定id收货地址表信息")
    //@RequiresPermissions("user:address:update")
    public R update(@RequestBody AddressEntity address){
		addressService.updateById(address);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除指定id收货地址表信息")
    //@RequiresPermissions("user:address:delete")
    public R delete(@RequestBody Integer[] ids){
		addressService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
